home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / Var / Vars.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  19KB  |  795 lines

  1.  
  2. /*
  3. **  VARS.C
  4. **
  5. **    Variable Support for [X]DME
  6. **
  7. **  (C)Copyright 1992 by Bernd Noll for null/zero-soft
  8. **  All Rights Reserved
  9. **
  10. **  RCS Header: $Id: vars.c,v 1.65 92/11/09 12:47:10 b_noll Exp $
  11. **
  12. **  compiling with
  13. **  "#define PATCH_NULL"
  14. **  "#define PATCH_VARS"
  15. **  "#define PATCH_FLAGS"
  16. **  causes that module to be used (and var.c not to be used)
  17. **
  18. *!***************************************************************************
  19. *!
  20. *!  VARIABLES - OVERVIEW
  21. *!
  22. *!
  23. *!  the vars-module shall support access to different types of
  24. *!  variables
  25. *!  which are currently "special" vars/flags, "global" vars/flags,
  26. *!  "textlocal" vars/flags, "macrolocal" vars and "env" vars
  27. *!  also keybindings and menuitems are accessible via variables
  28. *!  in some versions of xdme also rexxclips, rexxvars, and macro-bodies
  29. *!  might be accessible via the variable interface, but that feature
  30. *!  has been dropped due to less feedback
  31. **  (there are some other types used for DME, but not for XDME yet)
  32. *!
  33. *!
  34. *!  WARNING:
  35. *!    as this module is written very close
  36. *!    to DME's internal hierachy, it will be object of major changes,
  37. **    as soon as Packages are introduced as a new concept for management
  38. **    of macros, menues, keys, flags and variables
  39. *!    in fact, that means, that funcionality is dropped as soon, as
  40. *!    the C-Interpreter is available
  41. *!
  42. *! some of the different VARIABLE command are following ...
  43. *!
  44. **
  45. **
  46. **  GetTypedVar / SetTypedVar / VAR_...types/prefixes
  47. **
  48. **  the "Highlevel" interface to most other variable modules,
  49. **  which should most times be used in Programming -
  50. **  Cleanest Possiblility of Access to Variables of any Type.
  51. **
  52. **  We have put all variable functions, which do not need access
  53. **  to certain structures (rexx.../argstack...), together in that
  54. **  module and try to export only a very small interface, which
  55. **  should allow information hiding
  56. **
  57. **  this module should completely cover the "old" module var.c
  58. **  so I put var.c into '#ifndef PATCH_VARS'
  59. **
  60. *****************************************************************
  61. **
  62. **  Implementor's note
  63. **
  64. **    The module looks pretty ugly,
  65. **    I am not ready documenting and porting all
  66. **    functions which had been written for DME
  67. **    into XDME partly as many differences have occurred
  68. **    partly as I have started designing a Packages-concept
  69. **
  70. **  XDME NOTE - the flags - routines are not used yet for XDME
  71. */
  72.  
  73. /**************************************
  74.         Includes
  75. **************************************/
  76. #include "defs.h"
  77.  
  78.  
  79. /**************************************
  80.        Internal Prototypes
  81. **************************************/
  82. Prototype void        init_variables  (void);
  83. Prototype char *    GetTypedVar     (char *, int *);
  84. Prototype void        SetTypedVar     (char *, char *, int);
  85. extern      void        SetDMEVar        (char *, char *);   /* Proto'd for access from scanf.c */
  86. extern      void        SetTextVar        (char *, char *);
  87. extern      void        SetDEnv        (char *, char *);
  88. extern      char *    GetDMEVar        (char *);
  89. extern      char *    GetTextVar        (char *);
  90. extern      char *    GetEnvVar        (char *);
  91. extern      char *    GetDEnv        (char *);
  92. Prototype void        do_set        (void);
  93. Prototype void        do_unset        (void);
  94. Prototype void        do_setenv        (void);
  95. Prototype void        do_unsetenv     (void);
  96. Prototype void        do_settvar        (void);
  97. Prototype void        do_unsettvar    (void);
  98. Prototype int        is_tflagset     (int);              /* Proto'd for access from control.c */
  99. Prototype int        is_gflagset     (int);              /* Proto'd for access from control.c */
  100. extern      char *    GetTextFlag     (char *);
  101. extern      char *    GetGlobalFlag   (char *);
  102. extern      char        SetAnyFlag        (char *, char *);
  103. extern      char        SetGlobalFlag   (char *, char *);
  104. extern      char        SetTextFlag     (char *, char *);
  105. Prototype void        do_flag        (void);
  106. Prototype void        do_toggleflag   (void);
  107. Prototype char *    getvar        (char *);
  108.  
  109.  
  110. /**************************************
  111.         Internal Variables
  112. **************************************/
  113. #ifndef VAR_NUM
  114. #define VAR_NUM 8
  115. #endif
  116.  
  117. #ifndef SIGN_LOCAL_FLAG
  118. # define SIGN_LOCAL_FLAG 't'
  119. #endif
  120.  
  121. #ifdef DBASE
  122. # define SList      DmeBase.SList
  123. # define VarsTree DmeBase.SList
  124. #else
  125. APTR    VarsTree = NULL;
  126. #endif
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /*
  134. **  init_variables()
  135. **    initialize the "global" variables structures
  136. **    call that function from main or make it '__autoinit'
  137. */
  138.  
  139. void
  140. init_variables (void)
  141. {
  142.     VarsTree = NULL;
  143. } /* init_variables */
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. /***************************************************************
  151. **
  152. **  Access to the different kinds of Named Variables
  153. **
  154. ***************************************************************/
  155.  
  156.  
  157.  
  158. /**************************************
  159. **  Handling of DME "global" Variables
  160. ** (if we are using Packages "global" might be the wrong name)
  161. **************************************/
  162.  
  163. char *
  164. GetDMEVar (char * name)
  165. {
  166.     return (GetVarFromTree(&VarsTree, name));
  167. } /* GetDMEVar */
  168.  
  169.  
  170.  
  171. void
  172. SetDMEVar (char * name, char * value)
  173. {
  174.     SetVarIntoTree (&VarsTree, name, value);
  175. } /* SetDMEVar */
  176.  
  177.  
  178.  
  179. /*
  180. *! >SET name value
  181. *! >UNSET name
  182. *!
  183. *!  set a std DME variable to a new value or drop it and its contents
  184. *!  if the name is only a number, set the according dme std flag
  185. *!
  186. *!  NOTE that if packages are ready, SET should default to PVars/PFlags,
  187. *!    not to GVars/GFlags
  188. *!
  189. */
  190.  
  191. void
  192. do_set (void)
  193. {
  194.     if (!SetGlobalFlag(av[1], av[2]))
  195.     SetDMEVar (av[1],av[2]);
  196. } /* do_set */
  197.  
  198.  
  199.  
  200. void
  201. do_unset (void)
  202. {
  203.     DelVarFromTree (&VarsTree, av[1]);
  204. } /* do_unset */
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211. /**************************************
  212. **  Handling of Text Local Variables
  213. **************************************/
  214.  
  215. char *
  216. GetTextVar (char * name)
  217. {
  218.     return (GetVarFromTree (&Ep->textvars, name));
  219. } /* GetTextVar */
  220.  
  221.  
  222.  
  223. void
  224. SetTextVar (char * name, char * value)
  225. {
  226.     SetVarIntoTree (&Ep->textvars, name, value);
  227. } /* SetTextVar */
  228.  
  229.  
  230.  
  231. /*
  232. *! >SETTVAR name value
  233. *! >UNSETTVAR name
  234. *!
  235. *!  set a text local variable to a new value or drop it and its contents
  236. *!  if the name is only a "t"number, set the according text local flag
  237. *!
  238. */
  239.  
  240. void
  241. do_settvar (void)
  242. {
  243.     if (!SetTextFlag(av[1], av[2]))
  244.     SetTextVar (av[1],av[2]);
  245. } /* do_settvar */
  246.  
  247.  
  248.  
  249. void
  250. do_unsettvar (void)
  251. {
  252.     DelVarFromTree (&Ep->textvars, av[1]);
  253. } /* do_unsettvar */
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260. /***************************************************************
  261. **
  262. **  Access to Environment variables
  263. **
  264. ***************************************************************/
  265.  
  266.  
  267.  
  268. char *
  269. GetDEnv (char * ename)
  270. {
  271.     long   envLock = Lock("env:", SHARED_LOCK);
  272.     char * str       = NULL;
  273.  
  274.     if (envLock)
  275.     {
  276.     long  oldLock = CurrentDir (envLock);
  277.     FILE * fi     = fopen (ename, "r");
  278.     long   siz;
  279.  
  280.     if (fi)
  281.     {
  282.         fseek (fi, 0L, 2);
  283.         siz = ftell (fi);
  284.         fseek (fi, 0L, 0);
  285.  
  286.         if (siz > 0 && (str = malloc (siz + 1)))
  287.         {
  288.         fread (str, siz, 1, fi);
  289.         str[siz] = 0;
  290.         } /* if malloced */
  291.         fclose (fi);
  292.     } /* if opened */
  293.     UnLock (CurrentDir (oldLock));
  294.     } /* if locked */
  295.     return (str);
  296. } /* GetDEnv */
  297.  
  298.  
  299.  
  300. void
  301. SetDEnv (char * ename, char * econt)
  302. {
  303.     long envLock = Lock ("env:", SHARED_LOCK);
  304.  
  305.     if (envLock)
  306.     {
  307.     long   oldLock = CurrentDir (envLock);
  308.     FILE * fi      = fopen (ename, "w");
  309.  
  310.     if (fi)
  311.     {
  312.         fwrite (econt, strlen(econt), 1, fi);
  313.         fclose (fi);
  314.     } /* if opened */
  315.     UnLock (CurrentDir(oldLock));
  316.     } /* if locked */
  317. } /* SetDEnv */
  318.  
  319.  
  320.  
  321. char *
  322. GetEnvVar(char * name)
  323. {
  324.     char * str;
  325.  
  326.     mountrequest(0);
  327.     str = GetDEnv(name);
  328.     mountrequest(1);
  329.     return(str);
  330. } /* GetEnvVar */
  331.  
  332.  
  333.  
  334. /*
  335. *! >SETENV name value
  336. *! >UNSETENV name
  337. *!
  338. *!  set an Environment variable to a new value or drop it and its contents
  339. */
  340.  
  341. void do_setenv (void)
  342. {
  343.     SetDEnv ((char *)av[1], (char *)av[2]);
  344. } /* do_setenv */
  345.  
  346.  
  347.  
  348. void do_unsetenv (void)
  349. {
  350.     char * tmp = malloc(4+1+strlen(av[1]));
  351.  
  352.     if (tmp)
  353.     {
  354.     strcpy(tmp, "ENV:");
  355.     strcat(tmp, av[1]);
  356.  
  357.     mountrequest (0);
  358.     DeleteFile ((STRPTR)tmp);
  359.     mountrequest (1);
  360.  
  361.     free (tmp);
  362.     } /* if */
  363. } /* do_unsetenv */
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370. /***************************************************************
  371. **
  372. **  Access to the different kinds of Flags
  373. **
  374. ***************************************************************/
  375.  
  376.  
  377. /**************************************
  378. **  Handling of TEXT Local Flags
  379. **************************************/
  380.  
  381. int is_tflagset(int num)
  382. {
  383.     return (IsFlagSet(Ep->textflags, num, 32));
  384. } /* is_tflagset */
  385.  
  386.  
  387.  
  388. char SetTextFlag(char * name, char *  value)
  389. {
  390.     return (SetFlag(Ep->textflags, name, value, 32, "t"));
  391. } /* SetTextFlag */
  392.  
  393.  
  394.  
  395. /*
  396.  *  GetTextFlag: get a variable of a text's internal flags
  397.  */
  398.  
  399. char * GetTextFlag (char * name)
  400. {
  401.     return (GetFlag(Ep->textflags, name, 32, "t"));
  402. } /* GetTextFlag */
  403.  
  404.  
  405.  
  406.  
  407.  
  408. #ifdef DBASE
  409. # define tg DmeBase.gflags
  410. #else
  411. char tg[MAXTOGGLE/8]; /* test purposes */
  412. #endif /* DBASE */
  413.  
  414. /**************************************
  415. **  Handling of DME Global Flags
  416. **************************************/
  417.  
  418. int is_gflagset (int num)
  419. {
  420.     return(IsFlagSet(tg, num, MAXTOGGLE));
  421. } /* is_gflagset */
  422.  
  423.  
  424.  
  425. /*
  426.  *  GetGlobalFlag : get a variable from dme's flag-list
  427.  */
  428.  
  429. char SetGlobalFlag(char * name, char * value)
  430. {
  431.     return(SetFlag(tg, name, value, MAXTOGGLE, "")); /* "g" */
  432. } /* SetGlobalFlag */
  433.  
  434.  
  435.  
  436. char * GetGlobalFlag (char * name)
  437. {
  438.     return(GetFlag(tg, name, MAXTOGGLE, ""));   /* "g" */
  439. } /* GetGlobalFlag */
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446. /**************************************
  447. **  Interface to come around with all types of flags
  448. **************************************/
  449.  
  450. char
  451. SetAnyFlag(char * name, char * qual)
  452. {
  453.     if (name && qual)
  454.     {
  455.     if (is_number(name))
  456.     {
  457.         return(SetGlobalFlag(name, qual));
  458.  
  459.     /* } if (!is_digit(name[1]))
  460.     {           // Commented out for XDME */
  461.     //     return(SetSpecialFlag(name, qual));  /* Commented out for XDME */
  462.  
  463.     } else if (name[0] == SIGN_LOCAL_FLAG)
  464.     {
  465.         return(SetTextFlag(name, qual));
  466.  
  467.     } else
  468.     {
  469.         /* abort(); */
  470.         return(0);
  471.     } /* if */
  472.     } else
  473.     {
  474.     abort(0);
  475.     } /* if */
  476. } /* SetAnyFlag */
  477.  
  478.  
  479.  
  480. /*
  481. *! >FLAG flagname on/off/toggle/switch/0/1/set/reset/true/false
  482. *!
  483. *!  set any flag that is controlled by DME
  484. *!  with flagname is number, "t"number or specialflagname
  485. *!
  486. */
  487.  
  488. void
  489. do_flag (void)
  490. {
  491.     if (!SetAnyFlag(av[1],av[2]))
  492.     abort2();
  493. } /* do_flag */
  494.  
  495.  
  496.  
  497. /*
  498. *! >[[RE]SET]TOGGLE flagname
  499. *!
  500. *!  modify any flag, that is controlled by DME
  501. *!  with flagname is number, "i"number or specialflag
  502. *!
  503. */
  504.  
  505. void
  506. do_toggleflag (void)
  507. {
  508.     SetAnyFlag(av[1], av[0]);
  509. } /* do_toggleflag */
  510.  
  511.  
  512.  
  513. /***************************************************************
  514. **
  515. **  Interface to be used for external functions and commands
  516. **
  517. ***************************************************************/
  518.  
  519.  
  520.  
  521. /*
  522. ** the different types of "variables",
  523. ** which seem to be possible to be recognized
  524. **
  525. ** these definitions must be visible to all modules
  526. */
  527.  
  528. // #define VAR_NEX 0  /* not existing variable */
  529. // #define VAR_FPK 1  /* explicite access to another ("foreign") package */
  530. // #define VAR_SF  2  /* dme special flags */
  531. // #define VAR_SI  3  /* dme special integer variable */
  532. // #define VAR_SV  4  /* dme special vars scanf/filename/... */
  533. // #define VAR_MF  5  /* dme macro   flag */
  534. // #define VAR_TF  6  /* dme text    flag */
  535. // #define VAR_PF  7  /* dme package flag */
  536. // #define VAR_GF  8  /* dme global  flag */
  537. // #define VAR_TV  9  /* dme text    variable */
  538. // #define VAR_MV  10 /* dme macro   variable */
  539. // #define VAR_PV  11 /* dme package variable */
  540. // #define VAR_GV  12 /* dme global  variable */
  541. // #define VAR_ARG 13 /* dme macro   parameter */
  542. // #define VAR_ENV 14 /* CBM env: variable */
  543. // #define VAR_SH  15 /* CBM local shell-var            (FUTURE) */
  544. // #define VAR_CLP 16 /* rexx cliplist - entry */
  545. // #define VAR_RXX 17 /* rexx variable via RVI */
  546. // #define VAR_RXF 18 /* rexx result of functioncall */
  547. // #define VAR_MAP 19 /* dme package key-mapping */
  548. // #define VAR_MEN 20 /* dme package menu */
  549. // #define VAR_MNX 21 /* Arp shell-var                (FUTURE) */
  550.  
  551. // #define VAR_DME VAR_GV /* alias */
  552.  
  553. #define VF_COP    1  /* duplicate the result */
  554. #define VF_PAW    2  /* Prefix AlWays: dont use without Prefix (FUTURE) */
  555.  
  556.  
  557. typedef struct _vtype
  558. {
  559.     const char * name;    /* prefix */
  560.     int     id;     /* number for communication */
  561.     int     len;    /* size of prefix for comparison */
  562.     int     offset;    /* offset to cut prefix */
  563.     int     flags;    /* flags (e.g. duplicate result ...) */
  564.     char*   replace;    /* if prefix matches, replace w/that prefix */
  565.     void    (*do_set)(char*,char*); /* set-function */
  566.     char*   (*do_get)(char*);       /* get-function */
  567. } VTYPE;
  568.  
  569.  
  570. static CONST VTYPE vartypes[] =
  571. {
  572. #ifdef N_DEF
  573.     {"SHVAR_",  VAR_SH , 6, 6,     0, NULL, NULL, NULL},
  574.     {"ARP_",    VAR_MNX, 4, 4,     0, NULL, NULL, NULL},
  575.     {"RXFUNC ", VAR_RXF, 7, 7,     0, NULL, NULL, getQ},
  576.     {"RXSFUNC ",VAR_RXF, 8, 8,     0, NULL, NULL, getQ},
  577. #endif
  578.     {"SFLAG_",  VAR_SF,  6, 6,     0, NULL,     (void (*)(char*,char*))SetSpecialFlag, GetSpecialFlag},    /* we need 3 names */
  579.     {"SINT_",   VAR_SI,  5, 5,     0, NULL,     (void (*)(char*,char*))SetSpecialInt,  GetSpecialInt},     /* for the 3 different types (or we have to put them together) */
  580.     {"SPC_",    VAR_SV,  4, 4,     0, NULL,     (void (*)(char*,char*))SetSpecialVar,  GetSpecialVar},     /* of special vars else there are big problems */
  581.     {"TFLAG_",  VAR_TF,  6, 6,     0, "t%s",    (void (*)(char*,char*))SetTextFlag,    GetTextFlag},
  582.     {"GFLAG_",  VAR_GF,  6, 6,     0, NULL,     (void (*)(char*,char*))SetGlobalFlag,  GetGlobalFlag},  /* ifdef PATCH_PACK set replace to "g%s" */
  583.     {"ARG_",    VAR_ARG, 4, 4,     0, "arg%s",  NULL,           getmacroarg},
  584.     {"arg",     VAR_ARG, 3, 0,     0, NULL,     NULL,           getmacroarg},
  585.     {"MVAR_",   VAR_MV,  5, 5,     0, NULL,     SetMacroVar,    getmacrovar},
  586.     {"TVAR_",   VAR_TV,  5, 5,     0, NULL,     SetTextVar,     GetTextVar},
  587.     {"GVAR_",   VAR_GV,  5, 5,     0, NULL,     SetDMEVar,      GetDMEVar},
  588.     {"ENV_",    VAR_ENV, 4, 4,     0, NULL,     SetDEnv,        GetEnvVar},
  589. #ifdef PATCH_RXCLIPS
  590.     {"RXCLP_",  VAR_CLP, 6, 6,     0, NULL,     SetRexxClip,    GetRexxClip},
  591. #endif /* PATCH_RXCLIPS */
  592. #ifdef PATCH_RXVARS
  593.     {"RXVAR_",  VAR_RXX, 6, 6,     0, NULL,     setrexxvar,     getrexxvar},
  594. #endif /* PATCH_RXVARS */
  595.     {"KEY_",    VAR_MAP, 4, 4,VF_COP, NULL,     (void (*)(char*,char*))mapkey,         keyspectomacro},
  596.     {"MENU_",   VAR_MEN, 5, 5,VF_COP, NULL,     NULL,           menutomacro},
  597.     {NULL,    VAR_NEX, 0, 0,       0, NULL,    NULL, NULL}
  598. };
  599.  
  600.  
  601.  
  602. /*
  603. **  GetTypedVar()
  604. **    this function is nearly the same as getvar from cmd2.c
  605. **    major differences:
  606. **    * it tells where it has found a variable;
  607. **    * first we check if the search-name matches a certain
  608. **      type-prefix and if it does, we use that type and its
  609. **      result (w/out respect if result != NULL)
  610. **    * then we check all types until we get a non-NULL result
  611. **      or an abortion
  612. **    * the end of the vartypes-list means - there is no variable
  613. **      of that name
  614. **    (type may be NULL)
  615. */
  616.  
  617. char *
  618. GetTypedVar (char * find, int *  type)
  619. {
  620.     char  * found    = NULL;
  621.     int     itype    = VAR_NEX;
  622.     VTYPE * vt;
  623.     char    inter_abort = globalflags.Abortcommand;
  624.  
  625.     if (type)
  626.     *type = VAR_NEX;
  627.  
  628.     if (find == NULL)
  629.     {        /* is there a name ? */
  630.     abort (NULL);
  631.     } else
  632.     if (find[0] == '\0')
  633.     { /* is it really a name ? */
  634.     return (NULL);
  635.     } /* if name corrupt */
  636.  
  637.     globalflags.Abortcommand = 0;
  638.  
  639. /* if (globalflags.debug) printf("\tgetvar %s ? prefix...", find); */
  640.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  641.     {
  642. /* if (globalflags.debug) printf("p"); */
  643.     if (strncmp(find, vt->name, vt->len) == 0)
  644.     {
  645.         char* ptr = find+vt->offset;
  646.         if (vt->replace)
  647.         {
  648.         sprintf(tmp_buffer, vt->replace, ptr);
  649.         ptr = tmp_buffer;
  650.         } /* if prefix replacement */
  651.         itype = vt->id;
  652.         found = (*vt->do_get)(ptr);
  653.         if (found)
  654.         {
  655. /* if (globalflags.debug) printf(" found prefix %s\n", vt->name); */
  656.         if (vt->flags & VF_COP)
  657.         {
  658.             found = strdup(found);
  659.         } /* if dup'd */
  660.         } else
  661.         {
  662. /* if (globalflags.debug) printf ("Aborting\n"); */
  663.         globalflags.Abortcommand = 1;
  664.         } /* if res(!)=0 */
  665.         goto gv_quit;
  666.     } /* if matching prefix */
  667.     } /* for all types */
  668.  
  669. /* if (globalflags.debug) printf(" direct..."); */
  670.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  671.     {
  672. /* if (globalflags.debug) printf("c"); */
  673.     if (vt->do_get)
  674.     {
  675.         if (found = (*vt->do_get)(find))
  676.         {
  677. /* if (globalflags.debug) printf("found type %s\n", vt->name); */
  678.         itype = vt->id;
  679.         if (vt->flags & VF_COP)
  680.         {
  681.             found = strdup(found);
  682.         } /* if dup'd */
  683.         goto gv_quit;
  684.         } /* if res#0 */
  685.     } /* if ex det-func */
  686.     } /* for all types */
  687.  
  688. gv_quit:
  689.  
  690. /* if (globalflags.debug) printf("\tgetvar:prefix/err/oerr/val == %s/%d/%d/%s\n",vt->name, (int)Abortcommand, (int)inter_abort, found); */
  691.  
  692.     globalflags.Abortcommand |= inter_abort;
  693.     if (type)
  694.     {
  695.     *type = itype;
  696.     }
  697.     return(found);
  698. } /* GetTypedVar */
  699.  
  700.  
  701.  
  702. /*
  703. **  Set a Variable
  704. **    if it has a known type, use the associated set-command
  705. **    else check if there is a matching prefix
  706. **    if nothing fits - abort
  707. */
  708.  
  709. void
  710. SetTypedVar (char * name, char * value, int type)
  711. {
  712.     VTYPE* vt;
  713.  
  714.     if ((name == NULL) || (name[0] == '\0'))
  715.     { /* is it a name ? */
  716.     abort2 ();
  717.     } /* if name corrupt */
  718.  
  719.     if (type == VAR_NEX)
  720.     {
  721.     for (vt = vartypes; vt->id != VAR_NEX && globalflags.Abortcommand == 0; vt++)
  722.     {
  723.         if (strncmp(name, vt->name, vt->len) == 0)
  724.         {
  725.         char* ptr = name+vt->offset;
  726. /* printf("setting ano type %s\n", vt->name); */
  727.         if (vt->do_set != NULL && name[vt->offset] != 0)
  728.         {
  729.             if (vt->replace)
  730.             {
  731.             sprintf(tmp_buffer, vt->replace, ptr);
  732.             ptr = tmp_buffer;
  733.             } /* if prefix replacement */
  734.             (*vt->do_set)(ptr, value);
  735.             return;
  736.         } else
  737.         {
  738.             abort2();
  739.         } /* if (no) set-function */
  740.         } /* if matching prefix */
  741.     } /* for all types */
  742.     abort2();
  743.     } /* if unknown type */
  744.  
  745.     for (vt = vartypes; vt->id != VAR_NEX; vt++)
  746.     {
  747.     if (vt->id == type)
  748.     {
  749.         if (vt->do_set)
  750.         {
  751. /* printf("setting ok type %s\n", vt->name); */
  752.         if (strncmp(name, vt->name, vt->len) == 0)
  753.         {
  754.             char* ptr = name+vt->offset;
  755.             if (vt->replace)
  756.             {
  757.             sprintf(tmp_buffer, vt->replace, ptr);
  758.             ptr = tmp_buffer;
  759.             } /* if prefix replacement */
  760.             (*vt->do_set)(ptr, value);
  761.         } else
  762.         {
  763.             (*vt->do_set)(name, value);
  764.         } /* if (no) matching prefix */
  765.         return;
  766.         } else
  767.         {
  768.         abort2();
  769.         } /* if (no) set-function */
  770.     } /* if id found */
  771.     } /* for all types */
  772.  
  773.     abort2();
  774. } /* SetTypedVar */
  775.  
  776.  
  777.  
  778. /*
  779. **  Search
  780. **  (1) special Variables (2) Flags (3) macro's list,
  781. **  (4) text's list, (5) internal list, (6) enviroment,
  782. **  (7) Rexx cliplist (8) macros.  The variable is allocated
  783. **  with malloc().  NULL if not found.  ENV: need not exist.
  784. */
  785.  
  786. char * getvar (char * find)
  787. {
  788.     return (GetTypedVar(find,NULL));
  789. } /* getvar */
  790.  
  791.  
  792. /******************************************************************************
  793. *****  END vars.c
  794. ******************************************************************************/
  795.